package service;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import pojo.User;

public class UserServiceImpl implements UserService{
	public List<User> list=new ArrayList<User>();

	@Override
	public User addUser(User u) {
		synchronized (u) {
			u.setId(UUID.randomUUID().toString());
			list.add(u);
		}
		
		
		return u;
	}

	@Override
	public List<User> getUsers() {
		
		return list;
	}

	@Override
	public List<User> deleteUser(String id) {
		for (User u:list) {
			if (id.equals(u.getId())) {
				list.remove(u);
				return list;
			}
		}
		return list;
		
	}

	@Override
	public User getUser(String id) {
		User user=null;
		for (User u:list) {
			if (id.equals(u.getId())) {
				user=u;
				return user;
			}
		}
		return user;
	}

}
